Repository navigation
Recommend PKCE and deprecate the client secret - #974
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: b2c8322e5a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Addressed all three Codex points, each folded into its origin commit:
Pushed as d785eb7. Portal check, 335 tests, and build green; api lint and publish dry run green; OpenAPI validates. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d785eb7b64
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
PKCE is now the recommended way to sign users in, and the Client Secret is deprecated for anything but server-to-server calls. - Add code_challenge and code_challenge_method to the authorize and device code requests, and code_verifier to the token and device token requests. - Make client_secret optional and deprecated on every /oauth body (token, refresh, device token, revoke), from one shared schema. - Add a note to every /oauth endpoint description pointing to the PKCE guide, and drop client_secret from the request tables.
Enforcing PKCE as the default makes a copied Client ID useless, so the portal now steers developers to it. - Add a PKCE guide at /docs/pkce, covering both the authorization code and device code flows, and link it from Authentication and Create an App. - Show a PKCE recommendation next to the Client Secret on the app page and mark the secret deprecated. When the API stops returning a secret, show a placeholder instead of an empty value. - Warn on the app page and in the app form when a redirect URI is not a public https:// address (custom schemes, http, localhost, out-of-band). - Leave deprecated fields out of generated request body samples, so client_secret no longer appears in the /oauth samples.
A missing PUBLIC_GITHUB_CLIENT_ID made the static env import fail, so the apps page returned a 500 in local dev. Read it from the dynamic public env instead, and disable the Connect GitHub buttons with a note when it is not set.
vladjerca
left a comment
There was a problem hiding this comment.
Validated the corrected OAuth contract and developer documentation: OpenAPI validation, API lint and publish dry run, plus developer formatting, type-check, build, and 335 tests all pass. The public documentation now matches the supported flows.
Reset your local branch before pushing again.
…optional Trakt deprecated the client secret on 2026-10-01 (trakt/trakt-api#974): apps created since then are PKCE-only and have no secret, and `client_secret` is now optional/deprecated on every /oauth body. The device flow still works for these apps — you just omit `client_secret` (the device_code is the proof of possession). PKCE itself isn't used by the device flow; it only exists in the authorization-code flow. Without this, a PKCE-only Client ID can't connect: isConfigured() required a secret and the token/refresh/revoke calls always sent one, which Trakt rejects. - client_secret is now optional on device/token, token refresh, and revoke (sent only when the app still has one, so legacy apps keep working). - isConfigured() requires only a Client ID. - OAuth requests target auth.trakt.tv per current Trakt docs; the data API stays on api.trakt.tv. - Settings: the Client Secret field is marked optional and no longer gates "Connect". Adds TraktPkceAuthTests covering the secret-less device-token/refresh request bodies, legacy-secret backward-compat, isConfigured, and the OAuth host. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
<!-- claude-projects-attribution: {"github_login":"bendrucker"} -->
_Requested by **Ben** · [project
thread](https://claude.ai/code/project/chan_01TWyQ8yB7mqhkPt3YqS4rif?thread=cmsg_01TWyQ8yB7mqhkPt3YqS4rif5Weg2UHc3iexFshwczPTxF)_
Before: the pipeline and the monitor read Trakt with only the client ID.
The first request of many hours drew a 429 with a `Retry-After` of up to
260s, even though the hub sends only two or three requests an hour.
After a 429, history and ratings stopped until the next hour, and the
monitor's Trakt probe failed.
After: both read Trakt as the account through OAuth, each with its own
Trakt application and grant. Trakt has no personal access token, so each
one links once through Trakt's device flow. Until a grant is stored, the
pipeline records `skip.missing_secret` for both Trakt kinds and the
nightly re-walk, and the monitor leaves Trakt out of its probe. Neither
Worker uses a client secret. Trakt deprecated them in favor of PKCE
([trakt-api#974](trakt/trakt-api#974)), and the
device and refresh calls send the client ID alone.
How, pipeline: `src/trakt/auth.ts` resolves the token once per
invocation from D1's `trakt_tokens`. It refreshes once six hours or less
remain on Trakt's 24-hour token. The grant lives in D1 rather than KV
because Trakt rotates the refresh token on every refresh, and an
eventually consistent read of a rotated token would be a dead
credential. Rotation drives the rest of the design:
- A refresh writes only over the row it read. If Trakt refuses a refresh
token that a concurrent invocation already spent (`invalid_grant`), the
losing invocation re-reads the row, immediately and again two seconds
later, to pick up the winner's token.
- Any refusal or failure before Trakt issues a grant falls back to the
token in hand while it has time left. Once that token lapses, the error
says what to fix. `invalid_grant` means re-run the login. Any other
refusal means the client ID and redirect URI don't match the Trakt
application.
- Once Trakt issues a grant, the old refresh token is spent. The D1
write retries. If it still fails, the invocation keeps the new token
rather than dropping it.
- A 429 from the token endpoint is a rate-limit stop with `resumeAt`.
Token endpoint failures carry `endpoint: "oauth"`, which keeps their
bodies out of R2, where only data pages are archived.
The device-flow routes are `POST /admin/trakt/login`, and
`/admin/trakt/login/poll` with `device_code` in a JSON body. They
exchange the code inside the Worker, so the grant never leaves it, and
the code never appears in a URL. Without a client secret, the code plus
the public client ID is enough to claim the grant. A refresh repeats
`TRAKT_REDIRECT_URI` (`https://bendrucker.me/`), which must be
registered on the app. A 429's message now names the limit from
`X-Ratelimit`, or says the header was missing.
How, monitor: `workers/monitor/src/trakt-auth.ts` is a trimmed copy of
the refresh logic with the same fallback and write retry. It has no
concurrency guard, since the monitor runs once an hour on its own. The
token resolves once per run, on first use. A D1 failure reading the
grant leaves Trakt out of the probe rather than failing the run. The
monitor has no admin surface, so `bun run monitor:trakt-login` runs the
device flow locally with the monitor's client ID. It writes the grant to
the monitor's D1 through a temporary file passed to `wrangler d1 execute
--remote`.
Setup after merge:
1. Register `https://bendrucker.me/` as a redirect URI on both Trakt
apps and remove `urn:ietf:wg:oauth:2.0:oob`.
2. Link each app:
```sh
ADMIN_TOKEN=... bun run trakt:login https://<worker-host>
bun run monitor:trakt-login
```
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01PjhteXVmB2DedotVunbH21
---------
Co-authored-by: Claude <noreply@anthropic.com>
…hed and bring in your watchlist Signing in is Trakt's device code with PKCE: only the Client ID is needed, since Trakt no longer issues a client secret to new apps (trakt/trakt-api#974). A secret from an older app is still sent. Titles from Trakt show only when one of the TV's apps has them, like TMDB's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…hed and bring in your watchlist Signing in is Trakt's device code with PKCE: only the Client ID is needed, since Trakt no longer issues a client secret to new apps (trakt/trakt-api#974). A secret from an older app is still sent. Titles from Trakt show only when one of the TV's apps has them, like TMDB's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Summary
Makes PKCE the recommended way to sign users in to Trakt, and starts phasing out the Client Secret for anything but server-to-server calls. With PKCE as the default, a copied Client ID can no longer be turned into tokens.
API reference (
@trakt/api)code_challengeandcode_challenge_methodon authorize, andcode_verifieron token.client_secretis now optional and marked deprecated on every/oauthbody (token, refresh, device token, revoke), from one shared schema.client_secretis removed from request tables.Developer portal
https://address (custom schemes,http://, localhost, out-of-band). Mobile apps are pointed to Universal Links and verified App Links. It warns but does not block saving.client_secretno longer appears in the/oauthsamples.PUBLIC_GITHUB_CLIENT_IDis not set. Connect GitHub is disabled with a note instead. The ID is now read from the dynamic public env, which the static build writes to/_app/env.js. @vladjerca feel free to revert that commit, I just needed that to test locally 👨🔬Notes for reviewers
@trakt/apichange needs a version tag to publish.Test plan
deno task check,deno task test(325 passing),deno task build, and both format checks inprojects/developerdeno fmt --check,deno lint, anddeno task publish:checkinprojects/apideno task openapi:validate/docs/pkcerenders and shows in the sidebarpostOauthTokensample body has noclient_secret, and the note renders on the/oauthendpoints/appsloads withoutPUBLIC_GITHUB_CLIENT_IDLocal testing screenshots